package com.loiot.baqi.service.job;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.loiot.baqi.commons.message.email.EmailClient;
import com.loiot.baqi.commons.message.email.SimpleEmailVo;
import com.loiot.baqi.constant.ApplicationConst;
import com.loiot.baqi.dao.AccountDao;
import com.loiot.baqi.dao.ZpCompanyJobInfoDao;
import com.loiot.baqi.dao.ZpDictionaryInfoDao;
import com.loiot.baqi.dao.ZpJlExpandInfoDao;
import com.loiot.baqi.dao.ZpJlInfoDao;
import com.loiot.baqi.pojo.ZpCompanyJobInfo;
import com.loiot.baqi.pojo.ZpDictionaryInfo;
import com.loiot.baqi.status.AccountType;
import com.loiot.baqi.status.CompanyJobSourceType;
import com.loiot.baqi.status.HeartbeatJobType;
import com.loiot.baqi.status.JlAuditType;
import com.loiot.baqi.status.PauseStartType;
import com.loiot.baqi.status.RecommendFlowType;
import com.loiot.baqi.utils.HtmlUnitUtil;
import com.loiot.baqi.utils.JsonToObject;
import com.loiot.baqi.utils.JsonUtils;
import com.loiot.baqi.utils.MD5Util;
import com.loiot.baqi.vo.hd.Root;
import com.loiot.commons.utils.DateUtil;
import com.loiot.commons.utils.StringUtil;
import com.timeloit.pojo.Account;
/**
 * 通知技术经理评审简历
 * @author Administrator
 *
 */
@Service("nodifyTechnologyAuditJob")
@Scope("prototype")
public class NodifyTechnologyAuditJob extends JobTaskDefine {

	@Resource
	private ZpCompanyJobInfoDao zpCompanyJobInfoDao;
	@Resource
	private ZpDictionaryInfoDao zpDictionaryInfoDao;
	
	@Resource
	private ZpJlInfoDao zpJlInfoDao;
	
	
	private Logger log = LoggerFactory.getLogger(this.getClass());
	
	/**
     * 账号数据访问接口
     */
    @Resource
    private AccountDao accountDao;
    
    @Resource
    ZpJlExpandInfoDao zpJlExpandInfoDao;
	  
	
	@Override
	public void doTask() {
		try {
			nodifyTechnologyAuditJob();
    	} catch (Exception e) {
			this.exceptionContent=e.getMessage();
		}finally{
			//添加心跳
			this.jobType=(int)HeartbeatJobType.NODIFY_TECHNOLOGY_AUDIT_JOB.getCode();
			this.addHeartbeat();
		}	
	}
	
	
	
	
	 public void nodifyTechnologyAuditJob() throws Exception{
	    	HashMap<String, Object> pMap = new HashMap<String, Object>();
	    	pMap.put("auditTypeId", JlAuditType.WAIT_AUDIT.getCode());
	    	List<HashMap<String, Object>> list = zpJlExpandInfoDao.queryNotAuditJl(pMap);
	    	if(list!=null && list.size()>0){
	    		for(HashMap<String,Object> map : list){
	    			int jlcount=Integer.parseInt(String.valueOf(map.get("jlcount")));
	    			String nickname=String.valueOf(map.get("nickname"));
	    			String email=String.valueOf(map.get("email"));
	    			 if(email!=null && StringUtil.isEmail(email) ){
	    				 SimpleEmailVo vo = new SimpleEmailVo();
	        			 vo.addEmail(email);
	                     vo.setTitle("憬仪评审通知");
	                     vo.setContent(ApplicationConst.getMessage("10101", nickname,String.valueOf(jlcount)));
	                     emailClient.sendT(vo);
	                     Thread.sleep(10000);
	                     log.info("发送时间："+DateUtil.toString(DateUtil.getNow(), DateUtil.DEFAULT_LONG_FORMAT));
	    			 }
	    		}
	    	}
	    }
}
